//
//  LGRevisePasswordController.m
//  BreathTrainingTool
//
//  Created by 1234 on 2024/5/21.
//  修改密码

#import "LGRevisePasswordController.h"

@interface LGRevisePasswordController ()
/**   */
@property (nonatomic , strong)UILabel *titleLabel1;
/**   */
@property (nonatomic , strong)UITextField *passwordTF1;

/**   */
@property (nonatomic , strong)UILabel *titleLabel2;
/**   */
@property (nonatomic , strong)UITextField *passwordTF2;

/**   */
@property (nonatomic , strong)UILabel *tipLabel;
/**   */
@property (nonatomic , strong)UIButton *saveBtn;

@end

@implementation LGRevisePasswordController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"修改密码";
    [self createSubView];
}

-(void)saveButtonAction{
    if (![self.passwordTF1.text isEqualToString:self.passwordTF2.text]) {
        self.tipLabel.hidden = NO;
        return;
    }
    self.tipLabel.hidden = YES;
    [RequestUtil withPOST:@"brbot-user/update-password-new" parameters:@{@"newPassword":self.passwordTF1.text.md5String,@"newPassword1":self.passwordTF2.text.md5String} header:YES success:^(NSInteger code, NSString *message, id returnData) {
        if (code == 200) {
            [TooltipView showMessage:@"修改成功" offset:0];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }else{
            [TooltipView showMessage:message offset:0];
        }
    } error:^(NSError *error) {
        [TooltipView showMessage:@"保存失败，请重试" offset:0];
    }];
}

-(void)createSubView{
    self.view.backgroundColor = [UIColor whiteColor];
    UILabel *titleLabel1 = [UILabel lableWithText:@"请输入新密码" colorString:@"#282828" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    titleLabel1.frame = CGRectMake(viewPix(16), viewPix(24), Screen_W-viewPix(32), viewPix(24));
    [self.view addSubview:titleLabel1];
    [self.view addSubview:self.passwordTF1];
    
    UILabel *titleLabel2 = [UILabel lableWithText:@"请确认新密码" colorString:@"#282828" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    titleLabel2.frame = CGRectMake(viewPix(16), viewPix(139), Screen_W-viewPix(32), viewPix(24));
    [self.view addSubview:titleLabel2];
    [self.view addSubview:self.passwordTF2];
    
    self.tipLabel = [UILabel lableWithText:@"两次密码输入不一致！" colorString:@"#F93D01" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    self.tipLabel.frame = CGRectMake(viewPix(16), viewPix(240), Screen_W-viewPix(32), viewPix(20));
    self.tipLabel.hidden = YES;
    [self.view addSubview:self.tipLabel];
    
    UIButton *saveBtn = [UIButton buttonWithTitle:@"完成" topMargin:Screen_H-topBarHeight-viewPix(88)];
    [saveBtn addTarget:self action:@selector(saveButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:saveBtn];
    
}

-(UITextField *)passwordTF1{
    if(!_passwordTF1){
        _passwordTF1 = [[UITextField alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(60), Screen_W-viewPix(32), viewPix(56))];
        _passwordTF1.backgroundColor = [UIColor colorWithString:@"#F2F1F8"];
        _passwordTF1.tintColor = [UIColor colorWithString:@"#282828"];
        _passwordTF1.textColor = [UIColor colorWithString:@"#282828"];
        _passwordTF1.textAlignment = NSTextAlignmentLeft;
        _passwordTF1.keyboardType = UIKeyboardTypeDefault;
        _passwordTF1.placeholder = @"请输入";
        _passwordTF1.cornerRidus = viewPix(28);
        _passwordTF1.secureTextEntry = YES;
        _passwordTF1.font = LGFontWeight(16, UIFontWeightMedium);
        _passwordTF1.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, viewPix(16), viewPix(56))];
        _passwordTF1.leftViewMode = UITextFieldViewModeAlways;
    }
    return _passwordTF1;
}

-(UITextField *)passwordTF2{
    if(!_passwordTF2){
        _passwordTF2 = [[UITextField alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(172), Screen_W-viewPix(32), viewPix(56))];
        _passwordTF2.backgroundColor = [UIColor colorWithString:@"#F2F1F8"];
        _passwordTF2.tintColor = [UIColor colorWithString:@"#282828"];
        _passwordTF2.textColor = [UIColor colorWithString:@"#282828"];
        _passwordTF2.textAlignment = NSTextAlignmentLeft;
        _passwordTF2.keyboardType = UIKeyboardTypeDefault;
        _passwordTF2.placeholder = @"请输入";
        _passwordTF2.cornerRidus = viewPix(28);
        _passwordTF2.secureTextEntry = YES;
        _passwordTF2.font = LGFontWeight(16, UIFontWeightMedium);
        _passwordTF2.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, viewPix(16), viewPix(56))];
        _passwordTF2.leftViewMode = UITextFieldViewModeAlways;
    }
    return _passwordTF2;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
